# Set default goal first
.DEFAULT_GOAL := targets

include $(CURDIR)/makelib/config.mk
include $(CURDIR)/makelib/marker.mk

SO_FILES = lib/autotcc.so

LUA_FILES = $(wildcard ./lua/*.lua)
LUA_MODULES = $(patsubst ./lua/%.lua, %, $(LUA_FILES))

#TARGETS = autotcc lunatic
TARGETS = lunatic
CLEAN_TARGETS = $(addprefix clean_, $(TARGETS))

DFILES = $(patsubst %.c, %.d, $(wildcard ./src/*.c))

.PHONY: $(TARGETS) $(CLEAN_TARGETS) build clean targets test

# Default target lists available targets and their intent.
targets:
	@echo "User-facing targets:"
	@echo "  build   - Build all test executables, reporting build timing."
	@echo "  clean   - Remove generated files."
	@echo "  targets - Display this help message.  (default)"
	@echo "  test    - Run test suite."
	@echo "As well as the following individual targets:"
	@echo "$(foreach target, $(TARGETS), $(shell printf '\t%s\\n' $(target)))"

build: $(TARGETS)

test: build
	LUA_PATH="lua/?.lua;tools/?.lua;tests/?.lua;;" lua5.4 test/lunatic-test.lua --quiet

include $(CURDIR)/makelib/autotcc.mk
include $(CURDIR)/makelib/lunatic.mk

clean: $(CLEAN_TARGETS)
	-@rm -f $(DFILES) 2>/dev/null || true

-include $(DFILES)
